package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.common.PlayerPool;
import com.xcity.game.vip.VipTemplate;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class VipListResponse extends Response {

	private int needMoneyToNextLvl; // 到下一vip等级需充值金额
	private List<VipInfo> list;
	
	public static class VipInfo extends VipTemplate {
		private byte state; // 该vip等级的礼包状态(-1:不能购买,0:未购买,1:已购买)
		public VipInfo(Player player, VipTemplate ref) {
			this.level = ref.getLevel();
			this.rechargeMoney = ref.getRechargeMoney();
			this.buyStrNum = ref.getBuyStrNum();
			this.stageAddedNum = ref.getStageAddedNum();
			this.turntableFreeNum = ref.getTurntableFreeNum();
			this.bagGridExtendNum = ref.getBagGridExtendNum();
			this.friendsMaxNum = ref.getFriendsMaxNum();
			this.headIcon = ref.getHeadIcon();
			this.buyBuildQueueNum = ref.getBuyBuildQueueNum();
			this.buyBuildQueueCost = ref.getBuyBuildQueueCost();
			this.circleFreeCount = ref.getCircleFreeCount();
			this.sweepCount = ref.getSweepCount();
			this.fullNormalStage = ref.getFullNormalStage();
			this.fullHeroStage = ref.getFullHeroStage();
			this.fullVigourCount = ref.getFullVigourCount();
			this.buyMoneyCount = ref.getBuyMoneyCount();
			this.captureBuildMaxCount = ref.getCaptureBuildMaxCount();
			this.gift = ref.getGift();
			if (player.getVipLvl() < level || gift == null) {
				state = -1;
			} else {
				int n = player.getPool().getIntValue(PlayerPool.PROPERTY_VIP_BUY_MARK);
				state = (byte) ((n >> level & 1) != 0 ? 1 : 0);
			}
		}
		public byte getState() {
			return state;
		}
		public void setState(byte state) {
			this.state = state;
		}
	}
	
	public VipListResponse(int serial, Player player, int needMoneyToNextLvl, List<VipTemplate> list) {
		super(serial);
		this.needMoneyToNextLvl = needMoneyToNextLvl;
		this.list = new ArrayList<VipInfo>(list.size());
		for (int i = 0; i < list.size(); i++) {
			this.list.add(new VipInfo(player, list.get(i)));
		}
	}

	public int getNeedMoneyToNextLvl() {
		return needMoneyToNextLvl;
	}

	public void setNeedMoneyToNextLvl(int needMoneyToNextLvl) {
		this.needMoneyToNextLvl = needMoneyToNextLvl;
	}

	public List<VipInfo> getList() {
		return list;
	}

	public void setList(List<VipInfo> list) {
		this.list = list;
	}
	
}
